package settingsapp.settings.continuous;

import settingsapp.ui.PanelGridActivity;
import android.media.AudioManager;
import android.util.Log;

/**
 * provides static methods which return SettingsChanger objects
 * with the given settings type
 */
public class ContinuousSettingFactory
{
	public static enum ContinuousSettingType
	{
		brightness("Brightness"),
		volumeMedia("Media Volume"),
		volumeSystem("System Volume"),
		volumeRinger("Ringer Volume"),
		volumeVoice("Call Volume"),
		unset("Unset");
		
		private final String description;
		
		private ContinuousSettingType(String description)
		{
			this.description = description;
		}
		
		public String toString() { return description; }
	}
	
	/**
	 * returns a SettingsChanger for the given SettingType
	 */
	public static ContinuousSettingChanger createSettingsObject(PanelGridActivity context, ContinuousSettingType type)
	{
		switch (type)
		{
		case brightness:
			return new SettingBrightness(context, 0);
		case volumeMedia:
			return new SettingVolume(context, AudioManager.STREAM_MUSIC, 1);
		case volumeRinger:
			return new SettingVolume(context, AudioManager.STREAM_RING, 2);
		case volumeSystem:
			return new SettingVolume(context, AudioManager.STREAM_SYSTEM, 3);
		case volumeVoice:
			return new SettingVolume(context, AudioManager.STREAM_VOICE_CALL, 4);
		case unset:
			return new SettingBrightness(context, 6);
		default:
			return null;		// never happens
		}
	}
	
	/**
	 * returns a SettingsChanger for the given SettingType (same as index used i getSettingTypes())
	 */
	public static ContinuousSettingChanger createSettingsObject(PanelGridActivity context, int typeIndex)
	{
		Log.d("setting", "creating ContinuousSettingChanger with index " + typeIndex + " (" + ContinuousSettingType.values()[typeIndex] + ")");
		return createSettingsObject(context, ContinuousSettingType.values()[typeIndex]);
	}
	
	/**
	 * returns an array of the String representations of the different setting types
	 */
	public static CharSequence[] getSettingTypes()
	{
		final ContinuousSettingType[] settingTypes = ContinuousSettingType.values();
		final CharSequence[] items = new CharSequence[settingTypes.length];
		
		for (int i = 0; i < settingTypes.length; i++)
			items[i] = settingTypes[i].toString();
		
		return items;
	}
}
